package com.cw1.factory.factoryMethod.order;

import com.cw1.factory.factoryMethod.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @Author qiuMi
 * @description 披萨 - 订单
 * @Date 2022-10-06 23:38
 **/
public abstract class OrderPizza {

    /**
     * 披萨 - 创建
     * @param type 披萨类型
     * @return 披萨
     */
    public abstract Pizza createPizza(String type);

    public OrderPizza() {
        do {
            String type = getType();
            Pizza pizza = createPizza(type);
            if (pizza != null){
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }else {
                System.out.println("制作披萨失败");
                break;
            }
        } while (true);
    }

    /**
     * 获取披萨类型
     */
    private String getType(){
        System.out.println("请输入披萨类型2：");
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        String type = null;
        try {
            type = bufferedReader.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return type;
    }
}
